package com.taobao.ad.hadoop.common;

import java.util.*;
import org.dom4j.*;
import org.dom4j.io.*;

public class XmlParse {
	public static List<Map<String, String>> parse(String xmlconf)
			throws DocumentException {
		SAXReader saxReader = new SAXReader();
		Document document = saxReader.read(xmlconf);
		Element root = document.getRootElement();
		List<Map<String, String>> jobconfList = new ArrayList<Map<String, String>>();
		Iterator<?> jobIterator = root.element("Jobs").elementIterator("Job");
		while (jobIterator.hasNext()) {
			Element job = (Element) jobIterator.next();
			Iterator<?> kvIterator = job.elementIterator();
			Map<String, String> kvMap = new HashMap<String, String>();
			while (kvIterator.hasNext()) {
				Element kv = (Element) kvIterator.next();
				String name = kv.getName();
				String value = kv.getText();
				kvMap.put(name, value);
			}
			jobconfList.add(kvMap);
		}
		return jobconfList;
	}
}
